<template>
    <div class="actionBar" data-id="actionBar">
        <div :draggable="true" v-for="item in icons" :key="item.label" class="tag" :data-type="item.type" @dragstart="createNode($event,item)" @drop.prevent>
            <el-tooltip effect="dark" :content="item.label" placement="left">
            <svg class="icon" aria-hidden="true">
                <use :xlink:href="`#icon-${item.icon}`"></use>
            </svg>
            </el-tooltip>   
        </div>
    </div>
</template>

<script lang='ts' setup>
import { NodeItem } from '../props';
let icons: NodeItem[] = [
    {
        label: "圆形",
        type: "circle-node",
        icon: "yuanxingweixuanzhong",
        size: 40,
        style: {
            lineWidth: 2,
            cursor: "pointer"
        },
    },
    {
        label: "五角星",
        type: "star-node",
        icon: "wujiaoxingkong",
        size: 100,
        style: {
            lineWidth: 2,
            cursor: "pointer"
        },
    },
    {
        label: "长方形",
        type: "rect-node",
        icon: "tx-changfangxing",
        size: [100, 36],
        style: {
            lineWidth: 2,
            cursor: "pointer"
        },
    },
    {
        label: "三角形",
        type: "triangle-node",
        icon: "triangle",
        size: 40,
        style: {
            lineWidth: 2,
            cursor: "pointer"
        },
    },
    {
        label: "圆形容器",
        type: "circle",
        icon: "rongqifuwuContainerServi",
        size: [80, 80],
        style: {
            lineWidth: 2,
            cursor: "pointer"
        },
    },
    {
        label: "方形容器",
        type: "rect",
        icon: "rongqi",
        size: [80, 80],
        style: {
            lineWidth: 2,
            cursor: "pointer"
        },
    },
    {
        label: "自定义节点",
        type: "custom",
        icon: "yuanxingweixuanzhong",
    },
]
// 创建节点
const createNode = (event: DragEvent, item: NodeItem) => {
    event.dataTransfer?.setData('nodeType',
        JSON.stringify(item),
    );
}

</script>

<style lang="less" scope>
.actionBar {
    background-color: inherit;
    position: absolute;
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
    padding: 20px 5px;
    box-shadow: 0px 0px 13px 0px #ccc;
    z-index: 3;
    background-color: transparent;

    .tag {
        .icon {
            padding: 10px;
            width: 60px;
            height: 60px;
            background-color: inherit;
            transition: all .5s;
            border-radius: 8px;
            cursor: pointer;

            &:hover {
                background-color: antiquewhite;
            }
        }
    }
}
</style>